﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataBaseLibrary.DBInterfaces;
using System.ComponentModel;


namespace DataBaseLibrary.DBObjectsFB
{
    public class RegistrInformation : DBFObject, IDBObject, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }


        String m_DopVin = "";
        public string DopVin
        {
            get
            {
                return m_DopVin;
            }
            set
            {
                m_DopVin = value;
                OnPropertyChanged(new PropertyChangedEventArgs("DopVin"));
            }
        }

        String m_StateRoom = "";
        public string StateRoom //Гос. номер (ТРАНЗИТ) 
        {
            get
            {
                return m_StateRoom;
            }
            set
            {
                m_StateRoom = value;
                OnPropertyChanged(new PropertyChangedEventArgs("StateRoom"));
            }
        }

        String m_NumberRegistrSert = "";
        /// <summary>
        /// Номер рег. св-ва
        /// </summary>
        public string NumberRegistrSert 
        {
            get
            {
                return m_NumberRegistrSert;
            }
            set
            {
                m_NumberRegistrSert = value;
                OnPropertyChanged(new PropertyChangedEventArgs("NumberRegistrSert"));
            }
        }

        /// <summary>
        /// Серия рег. св-ва
        /// </summary>
        String m_SeriesRegistrSert = "";
        public string SeriesRegistrSert
        {
            get
            {
                return m_SeriesRegistrSert;
            }
            set
            {
                m_SeriesRegistrSert = value;
                OnPropertyChanged(new PropertyChangedEventArgs("SeriesRegistrSert"));
            }
        }

        /// <summary>
        /// Дата выдачи рег. св-ва
        /// </summary>
        DateTime? m_DateRegistrSert = null;
        public DateTime? DateRegistrSert
        {
            get
            {
                return m_DateRegistrSert;
            }
            set
            {
                m_DateRegistrSert = value;
                OnPropertyChanged(new PropertyChangedEventArgs("DateRegistrSert"));
            }
        }


        /// <summary>
        /// Кем выдано рег. св-ва
        /// </summary>
        String m_IssuedByRegistrSert = "";
        public string IssuedByRegistrSert
        {
            get
            {
                return m_IssuedByRegistrSert;
            }
            set
            {
                m_IssuedByRegistrSert = value;
                OnPropertyChanged(new PropertyChangedEventArgs("IssuedByRegistrSert"));
            }
        }

        //====================================================================

        String m_NumberInsuranceCompany = "";
        /// <summary>
        /// Номер страх компании
        /// </summary>
        public string NumberInsuranceCompany
        {
            get
            {
                return m_NumberInsuranceCompany;
            }
            set
            {
                m_NumberInsuranceCompany = value;
                OnPropertyChanged(new PropertyChangedEventArgs("NumberInsuranceCompany"));
            }
        }

        /// <summary>
        /// Серия рег. св-ва
        /// </summary>
        String m_SeriesInsuranceCompany = "";
        public string SeriesInsuranceCompany
        {
            get
            {
                return m_SeriesInsuranceCompany;
            }
            set
            {
                m_SeriesInsuranceCompany = value;
                OnPropertyChanged(new PropertyChangedEventArgs("SeriesInsuranceCompany"));
            }
        }

        /// <summary>
        /// Дата выдачи рег. св-ва
        /// </summary>
        DateTime? m_DateInsuranceCompany = null;
        public DateTime? DateInsuranceCompany
        {
            get
            {
                return m_DateInsuranceCompany;
            }
            set
            {
                m_DateInsuranceCompany = value;
                OnPropertyChanged(new PropertyChangedEventArgs("DateInsuranceCompany"));
            }
        }


        /// <summary>
        /// Серия рег. св-ва
        /// </summary>
        String m_IssuedByInsuranceCompany = "";
        public string IssuedByInsuranceCompany
        {
            get
            {
                return m_IssuedByInsuranceCompany;
            }
            set
            {
                m_IssuedByInsuranceCompany = value;
                OnPropertyChanged(new PropertyChangedEventArgs("IssuedByInsuranceCompany"));
            }
        }





        //====================================================================



        String m_SeriesPts = "";
        public string SeriesPts
        {
            get
            {
                return m_SeriesPts;
            }
            set
            {
                m_SeriesPts = value;
                OnPropertyChanged(new PropertyChangedEventArgs("SeriesPts"));
            }
        }

        String m_NumberPts = "";
        public string NumberPts
        {
            get
            {
                return m_NumberPts;
            }
            set
            {
                m_NumberPts = value;
                OnPropertyChanged(new PropertyChangedEventArgs("NumberPts"));
            }
        }

        DateTime? m_DateIssuePts = null;
        public DateTime? DateIssuePts
        {
            get
            {
                return m_DateIssuePts;
            }
            set
            {
                m_DateIssuePts = value;
                OnPropertyChanged(new PropertyChangedEventArgs("DateIssuePts"));
            }
        }

        String m_IssueByPts = "";
        public string IssueByPts
        {
            get
            {
                return m_IssueByPts;
            }
            set
            {
                m_IssueByPts = value;
                OnPropertyChanged(new PropertyChangedEventArgs("IssueByPts"));
            }
        }

        public RegistrInformation()
        {
            NameTable = "REGISTR_INFORMATION_TABLE";

            DopVin = "";
            StateRoom = "";
            NumberRegistrSert = "";
            SeriesRegistrSert = "";
            DateRegistrSert = null;
            SeriesPts = "";
            NumberPts = "";
            DateIssuePts = null;
            IssueByPts = "";
        }

        private void CreateData()
        {
            Parameters = new Dictionary<string, object>();
            Parameters.Add("DOP_VIN", DopVin);
            Parameters.Add("STATE_ROOM", StateRoom);


            Parameters.Add("NUMBER_REGISTR_CERT", NumberRegistrSert);
            Parameters.Add("SERIES_REGISTR_CERT", SeriesRegistrSert);
            Parameters.Add("DATE_ISSUE_REGISTR_CERT", DateRegistrSert);
            Parameters.Add("ISSUED_BY_REGISTR_CERT", IssuedByRegistrSert);

            Parameters.Add("NUMBER_INSURANCE_DOCUMENT", NumberInsuranceCompany);
            Parameters.Add("SERIES_INSURANCE_DOCUMENT", SeriesInsuranceCompany);
            Parameters.Add("DATE_ISSUE_INSURANCE_DOCUMENT", DateInsuranceCompany);
            Parameters.Add("ISSUED_BY_INSURANCE_DOCUMENT", IssuedByInsuranceCompany);

            Parameters.Add("SERIES_PTS", SeriesPts);
            Parameters.Add("NUMBER_PTS", NumberPts);
            Parameters.Add("DATE_ISSUE_PTS", DateIssuePts);
            Parameters.Add("ISSUE_BY_PTS", IssueByPts);


        }

        object IDBObject.Save()
        {
            try
            {
                CreateData();
                return SaveObject();
            }
            catch (SystemException)
            {
                throw new SystemException(String.Format("Ошибка при сохранении объекта {0} в БД", this.ToString()));
            }
        }

        void IDBObject.Load(object ID)
        {
            try
            {
                CreateData();
                LoadObject(ID);

                DopVin = Parameters["DOP_VIN"].ToString();
                StateRoom = Parameters["STATE_ROOM"].ToString();
                NumberRegistrSert = Parameters["NUMBER_REGISTR_CERT"].ToString();
                SeriesRegistrSert = Parameters["SERIES_REGISTR_CERT"].ToString();
                DateRegistrSert = Parameters["DATE_ISSUE_REGISTR_CERT"] == null || Parameters["DATE_ISSUE_REGISTR_CERT"].ToString() == String.Empty ? (DateTime?)null : DateTime.Parse(Parameters["DATE_ISSUE_REGISTR_CERT"].ToString());
                IssuedByRegistrSert = Parameters["ISSUED_BY_REGISTR_CERT"].ToString();

                NumberInsuranceCompany = Parameters["NUMBER_INSURANCE_DOCUMENT"].ToString();
                SeriesInsuranceCompany = Parameters["SERIES_INSURANCE_DOCUMENT"].ToString();
                DateInsuranceCompany = Parameters["DATE_ISSUE_INSURANCE_DOCUMENT"] == null || Parameters["DATE_ISSUE_INSURANCE_DOCUMENT"].ToString() == String.Empty ? (DateTime?)null : DateTime.Parse(Parameters["DATE_ISSUE_INSURANCE_DOCUMENT"].ToString());
                IssuedByInsuranceCompany = Parameters["ISSUED_BY_INSURANCE_DOCUMENT"].ToString();
                
                SeriesPts = Parameters["SERIES_PTS"].ToString();
                NumberPts = Parameters["NUMBER_PTS"].ToString();
                DateIssuePts = Parameters["DATE_ISSUE_PTS"] == null || Parameters["DATE_ISSUE_PTS"].ToString() == String.Empty ? (DateTime?)null : DateTime.Parse(Parameters["DATE_ISSUE_PTS"].ToString());
                IssueByPts = Parameters["ISSUE_BY_PTS"].ToString();

            }
            catch (SystemException)
            {
                throw new SystemException(String.Format("Ошибка при загрузке объекта {0} в БД", this.ToString()));
            }
        }


        void IDBObject.Update()
        {
            CreateData();
            UpdateObject();
        }
    }
}
